﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaiTu.IMessageServices
{
    /// <summary>
    /// 消息队列的客户端 继承自IMessageProducer
    /// </summary>
    public interface IMessageQueueClient:IMessageProducer
    {
        /// <summary>
        /// 发布 指定的消息到可持久化的队列中
        /// </summary>
        /// <param name="queueName"></param>
        /// <param name="message"></param>
        void Publish(string queueName,IMessage message);
        /// <summary>
        /// 发布指定的消息到易消失的队列中
        /// </summary>
        /// <param name="queueName"></param>
        /// <param name="message"></param>
        void Notify(string queueName,IMessage message);
        /// <summary>
        /// 从指定的队列中获取消息  通过同步阻塞的方式获取
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="queueName"></param>
        /// <param name="timeOut"></param>
        /// <returns></returns>
        IMessage<T> Get<T>(string queueName, TimeSpan? timeOut = null);
        /// <summary>
        /// 异步非阻塞的从队列中获取消息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="queueName"></param>
        /// <returns></returns>
        IMessage<T> GetAsync<T>(string queueName);
        /// <summary>
        /// 通知消息已成功的被接收或处理
        /// </summary>
        /// <param name="message"></param>
        void Ack(IMessage message);

        /// <summary>
        /// 消息没有处理成功
        /// </summary>
        /// <param name="message"></param>
        /// <param name="requeue"></param>
        /// <param name="exception"></param>
        void Nak(IMessage message,bool requeue,Exception exception=null);
        /// <summary>
        /// 从MQ 响应中创建一个类型消息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="mqResponse"></param>
        /// <returns></returns>
        IMessage<T> CreateMessage<T>(object mqResponse);
        /// <summary>
        /// 创建一个临时的队列用来进行请求或响应
        /// </summary>
        /// <returns></returns>
        string GetTempQueueName();
    }
}
